package  
{
	import flash.utils.getTimer;
	import org.flixel.plugin.photonstorm.BaseTypes.Bullet;
	import org.flixel.plugin.photonstorm.FlxWeapon;
	import org.flixel.plugin.photonstorm.FlxVelocity;
	/**
	 * ...
	 * @author Billy Kaifer
	 */
	public class HomingShot extends Weapon
	{
		[Embed(source = "../media/blue_bullet.png")]private var blue_bullet:Class;

		public var damage:int = 1;
		public var speed:int = 200;
		private var lastFired:uint = 0;
		private var nextFire:uint = 0;
		private var parent:*;
		
		public function HomingShot(name:String, parentRef:* = null, xVariable:String = "x", yVariable:String = "y") 
		{
			super(name, parentRef);
			parent = parentRef;
			this.makeImageBullet(100, blue_bullet, Registry.positionOffset.x, Registry.positionOffset.y, false, 16, -1, false, false);
			this.setBulletSpeed(speed);
			this.setBulletGravity(0, 0);
			this.setFireRate(fireRate);
			this.setBulletBounds(new FlxRect(0, 26, FlxG.width, FlxG.height))
		}
		
		override public function fire():Boolean {
			if (getFireRate() > 0 && (getTimer() < nextFire))
			{
				return false;
			}
			
			currentBullet = getFreeBullet();
			
			if (currentBullet == null) {
				return false;
			}
			
			var launchX:int = Registry.positionOffset.x;
			var launchY:int = Registry.positionOffset.y;
			
			launchX += Registry.player.x;
			launchY += Registry.player.y;
			
			currentBullet.velocity.x = 0;
			currentBullet.velocity.y = 0;
			
			lastFired = getTimer();
			nextFire = getTimer() + getFireRate();
			
			// Homing logic here
			//FlxVelocity.moveTowardsObject(currentBullet, , speed);
			
			bulletsFired++;
			
			return true;
		}
		
		override public function setParent(parentRef:*,xVariable:String,yVariable:String,offSetX:int = 0,offSetY:int = 0,useDirection:Boolean=false) {
			super.setParent(parentRef, xVariable, yVariable, offSetX, offSetY, useDirection);
			parent = parentRef;
		}
		
		override public function setBulletSpeed(speed:uint):void {
			super.setBulletSpeed(speed);
			this.speed = speed;
		}
	}

}